package de.szut.ita13.rs.wave.controller;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import de.szut.ita13.rs.wave.entity.Entity;
import de.szut.ita13.rs.wave.entity.Type;

public class KeyInput extends KeyAdapter {
	
	private Controller controller;
	
	public KeyInput(Controller controller) {
		this.controller = controller;
	}

	public void keyPressed(KeyEvent e) {
		int keyCode = e.getKeyCode();
		
		for(Entity entity : controller.entities) {
			if(entity.getType() == Type.Player) {
				if(keyCode == KeyEvent.VK_W) entity.setVelocityY(-5);
				if(keyCode == KeyEvent.VK_S) entity.setVelocityY(5);
				if(keyCode == KeyEvent.VK_D) entity.setVelocityX(5);
				if(keyCode == KeyEvent.VK_A) entity.setVelocityX(-5);
			}
		}
		
		if(keyCode == KeyEvent.VK_ESCAPE) System.exit(1);
		
	}
	
	public void keyReleased(KeyEvent e) {
		int keyCode = e.getKeyCode();
		
		for(Entity entity : controller.entities) {
			if(entity.getType() == Type.Player) {
				if(keyCode == KeyEvent.VK_W) entity.setVelocityY(0);
				if(keyCode == KeyEvent.VK_S) entity.setVelocityY(0);
				if(keyCode == KeyEvent.VK_D) entity.setVelocityX(0);
				if(keyCode == KeyEvent.VK_A) entity.setVelocityX(0);
			}
		}
	}
	
}
